Refactor FXIOS-15851 WindowManager tabManager API should return an optional value#33928
Conversation
|
+cc @lmarceau Since this is ultimately more of a Tab change than an actual WindowManager change. |
💪 Quality guardian3 tests files modified. You're a champion of test coverage! 🚀 🥇 Perfect PR sizeSmaller PRs are easier to review. Thanks for making life easy for reviewers! ✨ 🙌 Friday high-fiveThanks for pushing us across the finish line this week! 🙌 💬 Description craftsmanGreat PR description! Reviewers salute you 🫡 ✅ New file code coverageNo new file detected so code coverage gate wasn't ran. ✅ Existing file code coverageAll modified files meet their thresholds. Client.app: Coverage: 40.96
Generated by 🚫 Danger Swift against 35f4002 |
|
|
||
| /// Convenience. Provides opportunity for safety checks or window validation. | ||
| @MainActor | ||
| func windowExists(uuid: WindowUUID) -> Bool |
There was a problem hiding this comment.
Removed windowExists() because I think it was a code smell. Generally callers should not need to directly check this.
| defaults.set(tabCounts, forKey: entryPoint.defaultsKey) | ||
| } | ||
|
|
||
| /// It's possible for this telemetry helper to be called during onboarding flow before |
There was a problem hiding this comment.
That isn't a problem anymore (the comment) ?
There was a problem hiding this comment.
The tabManagerAvailable func was added as a safety check, but with these refactors that safety check is now baked into the tabManager(for:) func, so each call site is forced to handle the potential nil value. So with this function gone this comment doesn't really have a great place to live now, since we're checking the optional value separately in each call site. We could maybe add the comment to the top of the file if you think it's still worth calling out?
There was a problem hiding this comment.
Maybe we can do that yeah, I'll let you decide, you added that comment in the first place so you have more context than me! If you think it's useful to keep then lets move it, if not then 👋
There was a problem hiding this comment.
Yeah this was a good call-out thank you; I've moved the comment to the top of the file.
62b158b to
e052387
Compare
yoanarios
left a comment
There was a problem hiding this comment.
Changes look good just a small nit and unit test request
| @MainActor | ||
| private func startAtHomeCheck(windowUUID: WindowUUID) -> Bool { | ||
| let tabManager = windowManager.tabManager(for: windowUUID) | ||
| guard let tabManager = windowManager.tabManager(for: windowUUID) else { return false} |
There was a problem hiding this comment.
nit
| guard let tabManager = windowManager.tabManager(for: windowUUID) else { return false} | |
| guard let tabManager = windowManager.tabManager(for: windowUUID) else { return false } |
There was a problem hiding this comment.
Thank you, fixed
| wrappedManager.newBrowserWindowConfigured(windowInfo, uuid: uuid) | ||
| } | ||
|
|
||
| func tabManager(for windowUUID: WindowUUID) -> TabManager { |
There was a problem hiding this comment.
Code wise changes seems right my only ask it will be to add support in the mock to return nil and add at least a test in TabManagerMiddlewareTests that tests the nil value instead of force unwrap to cover that case
There was a problem hiding this comment.
I could be confused but isn't that a superfluous test? I don't think that actually exercises any real code in the client, right? LMK if I'm misunderstanding tho, I'm happy to update the unit tests.
There was a problem hiding this comment.
Fair point, I agree we don’t want to add a test that only validates the mock. My concern is more about the new API contract: tabManager(for:) now returns an optional, and TabManagerMiddleware is one of the consumers that needs to behave safely when that value is nil.
Right now the production implementation explicitly returns nil for invalid/missing windows instead of falling back to an unsafe tab manager, so I think it’s worth having at least one unit test that exercises a real consumer path with a nil TabManager. That would protect us from future regressions where someone forces unwrapping or assumes the tab manager always exists again.
There was a problem hiding this comment.
I've pushed up unit tests in 35f4002 but LMK if you had something else specific in mind.
|
🚀 PR merged to |
…tional value (mozilla-mobile#33928) * [FXIOS-15851] Refactor tabManager(for:) to return an optional value * Unit test updates * [FXIOS-15851] Comments * Spacing * [FXIOS-15851] Add unit tests
📜 Tickets
Jira ticket
💡 Description
Refactors the tabManager API in our
WindowManageradopters to return an optional value. I've kept the Sentry logging in that func in place, so that unexpected or invalid UUIDs should still be visible to us.Because we're still logging in that func, in most cases early returns are still reasonable and are preferable to us doing something like returning some other window's tabManager (which is very unsafe).
📝 Checklist